<title>layui 表格、表单函数</title>

<!-- input 标签函数 -->
#define input(name,type,value)
	<input class='layui-input' id='#(name)_id'  type="#(type??'text')" name='#(name??)'  value='#(value??)' lay-verType='tips'/>
#end

<!-- layui form表单默认样式输出函数 start -->
#define colStart(lable,xs)
 		<div class="layui-col-xs12 layui-col-sm6 layui-col-md#(xs??4)">
			<div class="layui-form-item">
				<label class="layui-form-label" #if(labelWidth) style="width:#(labelWidth??110)px;#if(labelWidth==0)display:none #end" #end title="#(lable??)" >#(lable??)#@star()</label>
				<div class="layui-input-block" #if(labelWidth)  style="margin-left:#(labelWidth??110)px" #end>
#end
<!-- label独占一行，textarea标签推荐使用此方法-->
#define colStartText(lable,xs)
 		<div class="layui-col-xs12 layui-col-sm6 layui-col-md#(xs??4)">
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label" #if(labelWidth) style="width:#(labelWidth??110)px;#if(labelWidth==0)display:none #end" #end title="#(lable??)" >#(lable??)#@star()</label>
				<div class="layui-input-block">
#end
			
#define colEnd()
				</div>
			</div>
		</div>
#end
<!-- layui div 默认样式输出函数 end -->
	
<!-- 输出星号 -->
#define star()
	#if(req)
		<font color="red">&nbsp;*</font>
		#set(req=false)
	#end
#end

<!-- form提交按钮 -->
#define submitButton()
	#@submitButton2(4)
#end
#define submitButton2(colNum)
 			<div class="layui-row layui-col-space1 task-row">
				<div class="layui-hide-xs layui-col-sm3 layui-col-md#(colNum??4)">
					<div class="layui-input-block"></div>	
				</div>
				<div class="layui-col-xs12 layui-col-sm9 layui-col-md#(12-colNum)">
					<div class="layui-input-block">
							<div class="layui-btn-container" style="margin-top: 10px;margin-left:-25px">
								<button id='submitBtn' type="submit" lay-submit	 class='layui-btn  layui-btn-normal '  value="Submit">
									<i class="layui-icon">&#xe605;</i>	提交
								</button>
								<button id='closeWinBtn' type="button" 	 class='layui-btn  layui-btn-normal' value="Close">
									<i class="layui-icon">&#x1006;</i>	关闭
								</button>
							</div>
					</div>
				</div>
			</div>
			#@submitFunction()   
 #end
 
 
 #define viewButton()
	#@viewButton2(4)
#end
#define viewButton2(colNum)
 			<div class="layui-row layui-col-space1 task-row">
				<div class="layui-hide-xs layui-col-sm3 layui-col-md#(colNum??4)">
					<div class="layui-input-block"></div>	
				</div>
				<div class="layui-col-xs12 layui-col-sm9 layui-col-md#(12-colNum)">
					<div class="layui-input-block">
							<div class="layui-btn-container" style="margin-top: 10px;margin-left:-25px">
							 
								<button id='closeWinBtn' type="button" 	 class='layui-btn  layui-btn-normal' value="Close">
									<i class="layui-icon">&#x1006;</i>	关闭
								</button>
							</div>
					</div>
				</div>
			</div>
			#@submitFunction()   
 #end
 
 
 
 
 
#define submitFunction()
<!-- 防止重复提交数据 -->
<script type="text/javascript">
		var num=0;
		$('#submitBtn').click(function() {
			if(num==1){
				$('#submitBtn').attr("disabled",true);						
			}
			num=1;
			//解决表单验证不通过的情况
			var timer = window.setInterval(function(){						
				$('#submitBtn').attr("disabled",false);
				num=0;window.clearInterval(timer);
			},3000);
		});
		
		//禁用回车提交事件
		/*document.onkeypress = function(){
			if(event.keyCode == 13) {
				return false;
			}
		}*/
</script>

#end
<!-- 分页条件查询表单 start -->
#define formStart()
<form class="layui-form layui-form-pane f-form #(hide_xs??'layui-hide-xs')" id='searchForm' lay-filter='searchForm' action="javascript:;">
	<div class='layui-row layui-col-space1 task-row search-model'>
		<div class='layui-col-xs12 layui-col-sm12 layui-col-md12'> 
			<div class="layui-form-item">
#end
#define formEnd()
				<div class="layui-inline">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-disabled #(search?'layui-hide':'')" disabled id="searchBtn_">
							<i class="layui-icon">&#xe615;</i>查询
						</button>
						<button class="layui-btn layui-hide" type="reset" id="resetBtn" style="margin-left: 5px!important;">
							<i class="layui-icon layui-icon-close"></i>重置
						</button>
						<button class="layui-btn #(reset?'layui-hide':'')" type="reset" onclick="$('#resetBtn').click();$('#searchBtn_').click()" style="margin-left: 5px!important;">
							<i class="layui-icon layui-icon-close"></i>清空
						</button>
						#@queryButton?()						
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
#end
<!-- 分页查询表单 end-->

<!-- 条件查询div start -->
#define queryStart(label)
		<div class="layui-inline" style="#(style)">
		    #if(showLabel==true)
			<label class="layui-form-label" for="#(label??)">#(label??)</label>
			<div class="layui-input-block">
			#end
#end
#define queryEnd()	
 			#if(showLabel==true)			
			 </div>
			#end
		</div>
#set(style="",showLabel=false)
#end
<!-- 条件查询div end -->

 <!-- 分页列表-->
#define table()
	<script type="text/html" id="table_toolbar">
		<div class="layui-btn-group #(toolbar == false ? 'layui-hide' : '')">
			#@buttonBefor?()
			<button class="layui-btn layui-btn-normal layui-btn-sm #(add == false ? 'layui-hide' : '')" lay-event="add">
				<i class="layui-icon">&#xe608;</i> 新增
			</button>				
			#@button?()		
			<button class="layui-btn  layui-btn-normal layui-btn-sm #(del == false ? 'layui-hide' : '')" lay-event="delete">
				<i class="layui-icon">&#xe640;</i> 删除
			</button>
			<button class="layui-btn layui-btn-normal layui-btn-sm #(refresh == false ? 'layui-hide' : '')" lay-event="refresh">
				<i class="layui-icon">&#xe669;</i> 刷新
			</button>
			#@buttonAfter?()		
		</div>					
	</script>

	<div class="layui-row  f-index-table">
		<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
			<!-- 默认列表 -->
 			<table id="maingrid" lay-filter="maingrid"></table>
		</div>
   	</div>
   	<!-- 	每行的操作按钮 -->
	<script type="text/html" id="bar_maingrid">
	#@buttonRowBefor?()
  	<a class="layui-btn layui-btn-xs #(edit == false ? 'layui-hide' : '')" lay-event="edit">编辑</a>
	#@buttonRow?()
  	<a class="layui-btn layui-btn-xs layui-btn-danger #(del == false ? 'layui-hide' : '')" lay-event="del">删除</a>
	#@buttonRowAfter?()
	</script>
#end

<!-- 表单上传按钮-->
#define formUploadButton(objectId,divId)
	### accept:指定允许上传时校验的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）;multiple:是否允许多选(true\false)
	changeDivContent('#(path)/portal/toFormUpload/#(objectId)-#(autoUpload??true)-#(showDelBtn??true)-#(accept??'file')-#(multiple??true)','#(divId)');
	#set(autoUpload=null,accept=null,showDelBtn=null,multiple=null)
#end
<!-- 查看附件列表 -->
#define getFormFileList(objectId,divId)
	changeDivContent('#(path)/portal/getFormFileList/#(objectId)','#(divId)');
#end
<!-- 是否下拉选项 -->
#define getSelectYesNo(name,value)
<select name="#(name)" class="layui-input">
	<option value=''>---#(text??'请选择')---</option>
	<option value='0' #if(value==0)selected="selected"#end>否</option>
	<option value='1' #if(value==1)selected="selected"#end>是</option>
</select>
#set(text='请选择')
#end

<!-- 是否单选项 -->
#define getRadioYesNo(name,value)
	<input type="radio" class="layui-input"  name="#(name)" value="0" checked="checked" title="否"/>
	<input type="radio" class="layui-input"  name="#(name)" value="1" #if(value==1)checked="checked" #end title="是"/>
#end
